<template>
  <div>
    <div class="container-top">
      <div class="top">
        <div class="title">政策文件</div>
      </div>
      <div class="search">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane label="全部" name="first"></el-tab-pane>
          <el-tab-pane label="最近一周" name="second"></el-tab-pane>
          <el-tab-pane label="最近一月" name="third"></el-tab-pane>
          <el-tab-pane label="本年" name="fourth"></el-tab-pane>
        </el-tabs>
      </div>
    </div>
    <ul class="container-list">
      <li v-for="(item, index) in zhengcelist" :key="index">
        <div class="list-main">
          <div class="main-img">
            <img src="@/assets/images/policy.png" alt="" />
          </div>
          <div class="main-text">
            <p class="title">{{ item.title }}</p>
            <p class="info">
              <i class="iconfont icon-yonghu"></i>
              <span>管理员</span>
              <span>{{ item.add_time | formatTime }}</span>
            </p>
          </div>
        </div>
        <div class="list-oper" @click="DetailsPage(item.a_id)">
          <i class="iconfont icon-qianwang"></i>
          <p>查看</p>
        </div>
      </li>
    </ul>
    <div class="block">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-count="total_page"
        :page-size="pageSize"
        layout="prev, pager, next,slot"
        :total="totalAll"
      >
        <el-input v-model="page"></el-input>
        <span @click="jumperPage()">GO</span>
      </el-pagination>
    </div>
  </div>
</template>
<script>
import moment from "moment";
import { ArtList } from "@/api/login";
export default {
  name: "ZhengCe",
  data() {
    return {
      // 当前页
      currentPage: 1,
      // 输入页码
      page: 1,
      // 总页数
      total_page: 0,
      // 每页显示个数
      pageSize: 6,
      // 总条数
      totalAll: 0,
      type: "0",
      token: '',
      zhengcelist: [],
      activeName: "first",
    };
  },
  filters: {
    formatTime(time) {
      return moment(time * 1000).format("YYYY-MM-DD");
    },
  },
  methods: {
    handleCurrentChange(val) {
      this.currentPage = val;
      this.queryArticleList();
    },
    handleClick(tab, event) {
      if (tab.name === "first") {
        this.type = "0";
      } else if (tab.name === "second") {
        this.type = "1";
      } else if (tab.name === "third") {
        this.type = "2";
      } else {
        this.type = "3";
      }
      this.queryArticleList();
    },
    queryArticleList() {
      ArtList({
        token: this.token,
        ac_id: 1,
        ispage: "1",
        type: this.type,
        page_no: this.currentPage,
        page_size: this.pageSize,
      }).then((result) => {
        const { data } = result;
        const { list } = data;
        this.zhengcelist = list;
        this.totalAll = data.count - 0;
        this.total_page = Math.ceil(this.totalAll / this.pageSize);
      });
    },
    DetailsPage(aid) {
      this.$router.push({
        path: "/details",
        query: {
          a_id: aid,
          jumppage: 'zhengce'
        },
      });
    },
    jumperPage() {
      if (this.page > this.total_page) {
        this.page = this.total_page;
        alert("超过总页数");
      }
      this.currentPage = this.page - 0;
    },
  },
  mounted() {
    const token = sessionStorage.getItem('token');
    this.token = token;
    this.queryArticleList();
  },
};
</script>
<style lang='scss' scoped>
img{
    width: 100%;
    height: 100%;
}
.container-top {
  .top {
    display: flex;
    margin-bottom: 30px;
    .title {
      font-size: 26px;
      font-family: "黑体";
      color: #5673ff;
      margin-right: 60px;
    }
  }
  .search {
    display: flex;
    & > div {
      margin-right: 45px;
    }
  }
  /deep/.el-tabs__header {
    margin: 0 !important;
  }
  /deep/.el-tabs__item {
    height: 35px;
    line-height: 35px;
    font-size: 18px;
    color: #a1a4b5;
  }
  /deep/.el-tabs__nav-wrap::after {
    background-color: transparent;
  }
  /deep/.el-tabs__item.is-active {
    color: #010101;
  }
  /deep/.el-tabs__active-bar {
    background-color: #5673ff;
  }
  /deep/.el-badge__content.is-fixed.is-dot {
    left: 2px;
    top: 5px;
  }
  /deep/.el-form-item {
    margin-bottom: 0;
    font-size: 16px;
  }
  /deep/.el-form-item__content {
    line-height: 0;
  }
  /deep/input::placeholder {
    color: #2b3139;
    font-family: "PingFang";
  }
  /deep/.el-input__suffix {
    top: 50%;
    transform: translateY(-50%);
  }
  /deep/.el-input__inner {
    padding: 6px 15px;
    line-height: 0;
    height: auto;
    font-size: 16px;
    font-family: "PingFang";
  }
  /deep/.el-button {
    padding: 11px 20px;
    background-color: #5672ff;
    border: none;
    font-family: "PingFang";
    font-weight: 700;
  }
  /deep/.el-input__icon {
    height: auto;
  }
  /deep/.el-select .el-input .el-select__caret {
    transform: none;
  }
  /deep/.el-icon-arrow-up:before {
    content: "\e615";
    font-family: "iconfont";
    font-size: 16px;
  }
}
.container-top,
.container-list li {
  padding: 33px 45px 20px;
  border-bottom: solid 1px #e7e9eb;
}
.container-list {
  li {
    display: flex;
    align-items: center;
    & > span {
      display: inline-block;
      padding: 7px 17px;
      margin-right: 45px;
      color: #fff;
      border-radius: 5px;
      font-size: 16px;
    }
    .purple {
      background: #bcc6fc;
    }
    .list-main {
      display: flex;
      width: 88%;
      .main-img {
        width: 110px;
        height: 60px;
        margin-right: 30px;
      }
      .main-text {
        .title {
          width: 830px;
          line-height: 35px;
          margin-bottom: 10px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          font-weight: 700;
          color: #2b3139;
        }
        .info {
          font-size: 16px;
          i {
            color: #5673ff;
            margin-right: 10px;
          }
          span {
            color: #9599a4;
            margin-right: 20px;
          }
        }
      }
    }
    .list-oper {
      text-align: center;
      color: #a1a4b5;
      cursor: pointer;
      i {
        font-size: 20px;
      }
      p {
        margin-top: 5px;
        font-size: 12px;
      }
    }
  }
}
.block {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  /deep/.el-input {
    width: 30px;
    height: 100%;
  }
  /deep/.el-input__inner {
    height: 25px;
    padding: 0;
    border: solid 1px #f0f1f4;
  }
  /deep/.el-pagination button,
  /deep/.el-pagination span,
  /deep/.el-pager li {
    height: 25px;
    line-height: 25px;
    color: #181b3b;
    font-weight: 700;
  }
  /deep/.el-pagination span {
    cursor: pointer;
  }
  /deep/.el-pagination.is-background .btn-next,
  /deep/.el-pagination.is-background .btn-prev,
  /deep/.el-pagination.is-background .el-pager li {
    background-color: #fff;
    border: solid 1px #f0f1f4;
    margin-right: 8px;
  }
  /deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
    color: #fff;
    background-color: #5272fd;
    border: solid 1px #3957fd;
    font-size: 16px;
  }
  span {
    display: inline-block;
    width: 35px;
    height: 25px;
    line-height: 25px;
    border: solid 1px #f0f1f4;
    margin-left: 8px;
    cursor: pointer;
    border-radius: 2px;
  }
}
/deep/.el-pagination {
  text-align: center;
}
</style>